package com.example.openplaydemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.openplaydemo.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'openplaydemo' library on application startup.
    static {
        System.loadLibrary("openplaydemo");
    }

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Example of a call to a native method
        TextView tv = binding.sampleText;
        tv.setText(stringFromJNI());
        //测试ffmpeg输出
        //tv.setText(testFFmpegCodecOutput());

       Button button = (Button) findViewById(R.id.ffmpeg_flow);
       button.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               testFFmpegFlow();
           }
       });

       //添加仅播放rgb数据的视图
        Button rgb_player = (Button) findViewById(R.id.ffmpeg_rgb_player);
        rgb_player.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,RGBPlayerActivity.class);
                //startActivityForResult(intent,1000);
                startActivity(intent);
            }
        });
        Button pcm = (Button) findViewById(R.id.ffmpeg_pcm_player);
        pcm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,PcmPlayer.class);
                startActivity(intent);
            }
        });

        //新增播放yuv视频文件
        Button yuv = (Button) findViewById(R.id.ffmpeg_yuv_player);
        yuv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转yuvPlayer
                Intent intent = new Intent(MainActivity.this,YuvPlayer.class);
                startActivity(intent);
            }
        });
        Button testAV = (Button) findViewById(R.id.ffmpeg_test);
        testAV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转yuvPlayer
                Intent intent = new Intent(MainActivity.this,OpenPlayAVAcrivity.class);
                startActivity(intent);
            }
        });
        Button op_player = (Button) findViewById(R.id.ffmpeg_op_play);
        op_player.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转yuvPlayer
                Intent intent = new Intent(MainActivity.this,TestOpenAVActivity.class);
                startActivity(intent);
            }
        });
    }

    /**
     * A native method that is implemented by the 'openplaydemo' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    /**
     * 测试ffmpeg 编解码器配置信息的
     * @return
     */
    public native String testFFmpegCodecOutput();

    public native String testFFmpegFlow();

    /**
     * 测试解复用视频文件
     */
   public native Void testDemuxMp4File(String filePath);

}